<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active{
      background-color: rgb(228, 246, 148);
    }
    .content{
      width: 200px;
      height: 200px;
      border: 1px solid #333;

      text-align: center;
      line-height: 200px;
    }
  </style>
</head>

<body>
  <div id="app">
    <button
      v-for="(title,index) in tabs.titles" 
      @click="switchTab(index)" 
      :class="{active: activeIndex === index}">
        {{ title }}
    </button>
   
    <div 
      v-for="(content, index) in tabs.content"
      class="content" 
      v-show="activeIndex === index">
      {{ content }}
    </div>
    
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data() {
        return {
          activeIndex: 0,
          tabs: {
            titles: ['标题1', '标题2', '标题3', '标题4'],
            content: ['内容1', '内容2', '内容3', '内容4']
          }
        }
      },
      methods: {
        switchTab(index) {
          this.activeIndex = index
        }
      }
    })
    app.mount('#app')
  </script>
</body>

</html>